﻿using System;
using Fabrication.ValueProviders;

namespace Fabrication
{
    public static class TimeRuleExtensions
    {
        public static IBuilderOptions<T> UseFutureTime<T>(this PropertySelector<T, DateTime> propertySelector, TimeSpan timeSpan)
        {
            var provider = new FunctionValueProvider<T, DateTime>(x => DateTime.Now.AddSeconds(RandomNumberGenerator.GetDouble(1, timeSpan.TotalSeconds)));
            return propertySelector.Use(provider);
        }

        public static IBuilderOptions<T> UseHistoricTime<T>(this PropertySelector<T, DateTime> propertySelector, TimeSpan timeSpan)
        {
            var provider = new FunctionValueProvider<T, DateTime>(x => DateTime.Now.AddSeconds(RandomNumberGenerator.GetDouble(1, timeSpan.TotalSeconds) * -1));
            return propertySelector.Use(provider);
        }

        public static IBuilderOptions<T> UseRange<T>(this PropertySelector<T, DateTime> propertySelector, TimeSpan timeSpan)
        {
            var totalSeconds = timeSpan.TotalSeconds;
            var provider = new FunctionValueProvider<T, DateTime>(x => DateTime.Now.AddSeconds(RandomNumberGenerator.GetDouble(totalSeconds - 1, totalSeconds)));
            return propertySelector.Use(provider);
        }
    }
}